def power(x, n=2):
    s = 1
    while n > 0:
        n = n - 1
        s = s * x
    return s


def add_end(L=[]):
    L.append('END')
    return L


def person(name, age, **kw):
    print("name:", name, "age:", age, "others:", kw)


def fun1(n):
    if n == 1:
        return 1
    if n == 2:
        return 2
    return fun1(n - 1) * fun1(n - 2)


list1 = [x * x for x in range(1, 11)]
print(list1)

list2 = [x * x for x in range(1, 11) if x % 2 == 0]
print(list2)

# 全排列算法
l1 = ['A', 'B', 'C']
l2 = ['X', 'Y', 'Z']
l = [m + n for m in l1 for n in l2]
print(l)

g = (x * x for x in range(10))
print(next(g))
print(next(g))
print(next(g))


def fib(m):
    n, a, b = 0, 0, 1
    while n < m:
        print(b)
        a, b = b, a + b
        n = n + 1
    return "done"


# fib(5)


def odd():
    print('step 1')
    yield 1
    print('step 2')
    yield (3)
    print('step 3')
    yield (5)


o = odd()
next(o)
next(o)


def abs(x):
    if x > - 0:
        return x
    else:
        return -x


def add(x, y, abs):
    return abs(x) + abs(y)


def fun1(x):
    return x * x


def lazy_sum(*args):
    def sum1():
        ax = 0
        for n in args:
            ax += n
        return ax

    return sum1()


l = map(fun1, [1, 2, 3, 4])
print(list(l))
print(add(1, -3, abs))

print(lazy_sum(1, 3, 4, 6))


def power(x):
    return x * x


def multiple(*numbers):
    sum = 0
    for n in numbers:
        sum = sum + n
    return sum


print(multiple(*[1, 2, 3]))
